import config from '@/config/config.js';
import http from '@/api/http.js'

let workShopRequest={
    loadWorkShops(workShop,page=1,limit=10,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.mdBaseUrl + "/workshop/list?page="+page + "&limit=" + limit;
            if(workShop){
                if(workShop.workShopCode){
                    url += "&workShopCode=" + workShop.workShopCode;
                }
                if(workShop.workShopName){
                    url += "&workShopName=" + workShop.workShopName;
                }
            }
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }
    }, save(workShop,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        if(token){
            let url = config.mdBaseUrl + "/workshop/save";
            http.post(url,workShop,callBack);
        }else{
            callBack(undefined);
        }
    }, updateWorkShopById(workShop,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workshop/update";
            http.put(url,workShop,callBack);
        } else {
            callBack(undefined);
        }
    }, selectById(workShopId,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workshop/selectById?workShopId=" + workShopId;
            http.get(url,callBack);
        } else {
            callBack(undefined);
        }
    }
    , deleteWorkShopById(workShopId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workshop/delete?workShopId=" + workShopId;
            http.delete(url,callBack);
        } else {
            callBack(undefined);
        }
    }, deletesWorkShop(workShopIds,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workshop/deletes?a=1";
            if(workShopIds){
                workShopIds.forEach(id=> url += '&workShopId='+id);
            }
            http.delete(url,callBack);
        } else {
            callBack(undefined);
        }
    }, ListWorkShops(callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/workshop/listWorkShops";
            http.get(url,callBack);
        } else {
            callBack(undefined);
        }
    }
}

export default workShopRequest;